<?php
/*
+--------------------------------------------------------------------------
|   AffiliStore 2
|   ========================================
|   Web: http://www.affilistore.com
|   Email: admin (at) affilistore (dot) com
|	License Type: AffiliStore 2 is NOT open source software and limitations apply 
|   Licence Info: Visit AffiliStore website and click on 'Licence'
+--------------------------------------------------------------------------
*/
// checks to see if password session is set
// if not redirects to ../admin/
if($_SESSION['loggedIn'] == 0 && !isset($adminPage)){
include('../includes/auth.inc.php');
}

// add a link
if (isset($_POST['addThisLink'])) {

	// check to see if details have been completed
	if (empty($_POST['ld_fullName']) || empty($_POST['ld_email']) || empty($_POST['ld_websiteURL']) || empty($_POST['ld_websiteTitle']) || empty($_POST['ld_websiteDescription']) || empty($_POST['ld_reciprocalLink'])) {
	$error = 1;

	} else {
	
	$timeNow = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
	$timeNextMonth =  mktime(0, 0, 0, date("m")+1, date("d"), date("Y"));
	
	$sql = sprintf("INSERT INTO affiliSt_links (name, email, url, title, description, category, reciprocal, confirmed, approved, added, nextcheck, nocheck) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %d, %s)",
			   quote_smart($_POST['ld_fullName']),
			   quote_smart($_POST['ld_email']),
			   quote_smart($_POST['ld_websiteURL']),
			   quote_smart($_POST['ld_websiteTitle']),
			   quote_smart($_POST['ld_websiteDescription']),
			   quote_smart($_POST['ld_category']),
			   quote_smart($_POST['ld_reciprocalLink']),
			   '1',
			   '1',
			   quote_smart($timeNow),
			   quote_smart($timeNextMonth),
			   quote_smart($_POST['ld_checkReciprocal']));
	mysql_query($sql, $databaseConnect) or die(mysql_error());
	
		// add 1 to categories links counter
		if ($_POST['ld_category'] != 'nocategory') {
		$sql =  sprintf("UPDATE affiliSt_linkcategories SET counter = counter + 1 WHERE id = %s",
					quote_smart($_POST['ld_category']));
		mysql_query($sql, $databaseConnect) or die(mysql_error());
		}
	
	}
}




// delete a link
if (isset($_GET['delete'])) {
$sql =  sprintf("DELETE FROM affiliSt_links WHERE id = %s",
           quote_smart($_GET['delete']));
mysql_query($sql, $databaseConnect) or die(mysql_error());

	// subtract one from parent subCategories counter
	if (isset($_GET['c']) && !isset($_GET['count'])) {
	$sql =  sprintf("UPDATE affiliSt_linkcategories SET counter = counter - 1 WHERE id = %s",
				quote_smart($_GET['c']));
	mysql_query($sql, $databaseConnect) or die(mysql_error());
	}
}







// edit a link
if (isset($_POST['editThisLink'])) {

	// check to see if details have been completed
	if (empty($_POST['ld_fullName']) || empty($_POST['ld_email']) || empty($_POST['ld_websiteURL']) || empty($_POST['ld_websiteTitle']) || empty($_POST['ld_websiteDescription']) || empty($_POST['ld_reciprocalLink'])) {
	$error = 1;

	} else {
	
	
	// check for recip link
	$findlink = @ implode('', file($_POST['ld_reciprocalLink']));
	if ($findlink) {
	
	$getBacklink = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'adLinkURL'");
	$userBacklink = mysql_fetch_assoc($getBacklink);
	$sitelink = $userBacklink['value'];
	
			if (eregi("$sitelink", $findlink)) {
			$recipConfirm = 1;
			} else {
			$recipConfirm = 0;
			}
		
	} else {
	$recipConfirm = 0;
	}
	
	
	// update the link
	$sql = sprintf("UPDATE affiliSt_links SET name = %s, email = %s, url = %s, title = %s, description = %s, category = %s, reciprocal = %s, confirmed = %s, approved = %s, nocheck = %s WHERE id = %s",
			   quote_smart($_POST['ld_fullName']),
			   quote_smart($_POST['ld_email']),
			   quote_smart($_POST['ld_websiteURL']),
			   quote_smart($_POST['ld_websiteTitle']),
			   quote_smart($_POST['ld_websiteDescription']),
			   quote_smart($_POST['ld_category']),
			   quote_smart($_POST['ld_reciprocalLink']),
			   quote_smart($recipConfirm),
			   quote_smart($_POST['ld_approve']),
			   quote_smart($_POST['ld_checkReciprocal']),
			   quote_smart($_POST['editThisLink']));
	mysql_query($sql, $databaseConnect) or die(mysql_error());
	
	
	
		// 1
		// links counter
		if ($_POST['ld_category'] != 'nocategory' && $_POST['ld_category'] != $_POST['oldCat'] && $_POST['oldApproveStatus'] == 1 && $_POST['ld_approve'] == 1) {
		
		// add new
		$sql =  sprintf("UPDATE affiliSt_linkcategories SET counter = counter + 1 WHERE id = %s",
					quote_smart($_POST['ld_category']));
		mysql_query($sql, $databaseConnect) or die(mysql_error());
		
		// minus old
		$sql =  sprintf("UPDATE affiliSt_linkcategories SET counter = counter - 1 WHERE id = %s",
					quote_smart($_POST['oldCat']));
		mysql_query($sql, $databaseConnect) or die(mysql_error());
		
		
		
		
		// 2
		} else if  ($_POST['ld_category'] != 'nocategory' && $_POST['ld_category'] != $_POST['oldCat'] && $_POST['oldApproveStatus'] == 1 && $_POST['ld_approve'] == 0) {
		
		// minus old
		$sql =  sprintf("UPDATE affiliSt_linkcategories SET counter = counter - 1 WHERE id = %s",
					quote_smart($_POST['oldCat']));
		mysql_query($sql, $databaseConnect) or die(mysql_error());
		
		
		
		
		
		
		// 3
		} else if  ($_POST['ld_category'] != 'nocategory' && $_POST['ld_category'] != $_POST['oldCat'] && $_POST['oldApproveStatus'] == 0 && $_POST['ld_approve'] == 1) {
		
		// minus old
		$sql =  sprintf("UPDATE affiliSt_linkcategories SET counter = counter + 1 WHERE id = %s",
					quote_smart($_POST['ld_category']));
		mysql_query($sql, $databaseConnect) or die(mysql_error());
		
			// get config details
			$getMyEmail = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'adEmail'");
			$myEmail = mysql_fetch_assoc($getMyEmail);
			$getEmailApprove = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'emailApprove'");
			$emailApprove = mysql_fetch_assoc($getEmailApprove);
			$getInstallDir = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'installDir'");
			$installDir = mysql_fetch_assoc($getInstallDir);
			$getEmailSig = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'emailSig'");
			$emailSig = mysql_fetch_assoc($getEmailSig);
		
			// approved email
			$myemailaddress = $myEmail['value'];
			$emailaddress = $_POST['ld_email'];
			$subject = "Link Exchange Approved";
			if ($_POST['ld_category'] != 'nocategory') {
			$linkLink = $installDir['value']."index.php?ld=1&cat=".$_POST['ld_category'];
			} else {
			$linkLink = $installDir['value']."index.php?ld=1";
			}
			$emailmessage = $emailApprove['value'];
			$emailfrom = $myemailaddress;
			$messagea .= "Dear ".$_POST['ld_fullName']."\n\n".$emailmessage."\n".$linkLink."\n\n".$emailSig['value']."\n\n";
			$runtime = (date("d M Y H:i"));
			$messagea .= "Time of the message: $runtime (server time zone)\n\n";
			mail($emailaddress, $subject, $messagea, "From: $emailfrom");
		
		
		
		
		
		// 4
		} else if  ($_POST['ld_category'] == 'nocategory' && $_POST['ld_category'] != $_POST['oldCat'] && $_POST['oldApproveStatus'] == 1 && $_POST['ld_approve'] == 1) {
		
		// minus old
		$sql =  sprintf("UPDATE affiliSt_linkcategories SET counter = counter - 1 WHERE id = %s",
					quote_smart($_POST['oldCat']));
		mysql_query($sql, $databaseConnect) or die(mysql_error());
		
		
		
		
		
		// 5
		} else if  ($_POST['ld_category'] == 'nocategory' && $_POST['ld_category'] != $_POST['oldCat'] && $_POST['oldApproveStatus'] == 1 && $_POST['ld_approve'] == 0) {
		
		// minus old
		$sql =  sprintf("UPDATE affiliSt_linkcategories SET counter = counter - 1 WHERE id = %s",
					quote_smart($_POST['oldCat']));
		mysql_query($sql, $databaseConnect) or die(mysql_error());
		
		
		
		
		
		// 6
		} else if  ($_POST['ld_category'] == 'nocategory' && $_POST['ld_category'] != $_POST['oldCat'] && $_POST['oldApproveStatus'] == 0 && $_POST['ld_approve'] == 1) {
		
			// get config details
			$getMyEmail = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'adEmail'");
			$myEmail = mysql_fetch_assoc($getMyEmail);
			$getEmailApprove = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'emailApprove'");
			$emailApprove = mysql_fetch_assoc($getEmailApprove);
			$getInstallDir = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'installDir'");
			$installDir = mysql_fetch_assoc($getInstallDir);
			$getEmailSig = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'emailSig'");
			$emailSig = mysql_fetch_assoc($getEmailSig);
		
			// approved email
			$myemailaddress = $myEmail['value'];
			$emailaddress = $_POST['ld_email'];
			$subject = "Link Exchange Approved";
			$linkLink = $installDir['value']."index.php?ld=1";
			$emailmessage = $emailApprove['value'];
			$emailfrom = $myemailaddress;
			$messagea .= "Dear ".$_POST['ld_fullName']."\n\n".$emailmessage."\n".$linkLink."\n\n".$emailSig['value']."\n\n";
			$runtime = (date("d M Y H:i"));
			$messagea .= "Time of the message: $runtime (server time zone)\n\n";
			mail($emailaddress, $subject, $messagea, "From: $emailfrom");
		
		
		
		
		
		
		
		
		// 7
		} else if  ($_POST['ld_category'] != 'nocategory' && $_POST['ld_category'] == $_POST['oldCat'] && $_POST['oldApproveStatus'] == 1 && $_POST['ld_approve'] == 0) {
		
		// minus unapproved
		$sql =  sprintf("UPDATE affiliSt_linkcategories SET counter = counter - 1 WHERE id = %s",
					quote_smart($_POST['ld_category']));
		mysql_query($sql, $databaseConnect) or die(mysql_error());
		
		
		
		
		
		
		// 8
		} else if  ($_POST['ld_category'] != 'nocategory' && $_POST['ld_category'] == $_POST['oldCat'] && $_POST['oldApproveStatus'] == 0 && $_POST['ld_approve'] == 1) {
		
		// add approved
		$sql =  sprintf("UPDATE affiliSt_linkcategories SET counter = counter + 1 WHERE id = %s",
					quote_smart($_POST['ld_category']));
		mysql_query($sql, $databaseConnect) or die(mysql_error());
		
		
		
			// get config details
			$getMyEmail = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'adEmail'");
			$myEmail = mysql_fetch_assoc($getMyEmail);
			$getEmailApprove = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'emailApprove'");
			$emailApprove = mysql_fetch_assoc($getEmailApprove);
			$getInstallDir = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'installDir'");
			$installDir = mysql_fetch_assoc($getInstallDir);
			$getEmailSig = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'emailSig'");
			$emailSig = mysql_fetch_assoc($getEmailSig);
		
			// approved email
			$myemailaddress = $myEmail['value'];
			$emailaddress = $_POST['ld_email'];
			$subject = "Link Exchange Approved";
			if ($_POST['ld_category'] != 'nocategory') {
			$linkLink = $installDir['value']."index.php?ld=1&cat=".$_POST['ld_category'];
			} else {
			$linkLink = $installDir['value']."index.php?ld=1";
			}
			$emailmessage = $emailApprove['value'];
			$emailfrom = $myemailaddress;
			$messagea .= "Dear ".$_POST['ld_fullName']."\n\n".$emailmessage."\n".$linkLink."\n\n".$emailSig['value']."\n\n";
			$runtime = (date("d M Y H:i"));
			$messagea .= "Time of the message: $runtime (server time zone)\n\n";
			mail($emailaddress, $subject, $messagea, "From: $emailfrom");
		
		
		}
		
		
		
		
	
	}
}









// check all for recip links
if (isset($_GET['checklinks'])) {

// get recip link pages query
$getRecipAll = mysql_query("SELECT * FROM affiliSt_links ORDER BY id ASC");
$allRecip = mysql_fetch_assoc($getRecipAll);

	do {
	
		if ($allRecip['nocheck'] == 0) {
		
			$findlink = @ implode('', file($allRecip['reciprocal']));
				if ($findlink) {

				// get backlink URL
				$getBacklink = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'adLinkURL'");
				$userBacklink = mysql_fetch_assoc($getBacklink);
				$sitelink = $userBacklink['value'];
				
						if (eregi("$sitelink", $findlink)) {
						$recipConfirm = 1;
						} else {
						$recipConfirm = 0;
						}
					
				} else {
				$recipConfirm = 0;
				}
				
			// update the recip link info
			$sql = sprintf("UPDATE affiliSt_links SET confirmed = %s WHERE id = %s",
					   quote_smart($recipConfirm),
					   quote_smart($allRecip['id']));
			mysql_query($sql, $databaseConnect) or die(mysql_error());
			
		}
	
	} while  ($allRecip = mysql_fetch_assoc($getRecipAll));
	
}







// pagination
$limit          = 50; 
$totalrows = mysql_result(mysql_query("SELECT COUNT(id) FROM affiliSt_links"),0);
 
$page = $_GET['page'];
$currentPage = $_SERVER["PHP_SELF"];

if(empty($page)){
$page = 1;
}
        
$limitvalue = $page * $limit - ($limit);














$getLinksDetails = mysql_query("SELECT * FROM affiliSt_links ORDER BY added DESC LIMIT $limitvalue, $limit");
$linksDetails = mysql_fetch_assoc($getLinksDetails);

$getCatNames = mysql_query("SELECT * FROM affiliSt_linkcategories ORDER BY name ASC");
$catNames = mysql_fetch_assoc($getCatNames);
?>





<?php
// error report
if ($error == 1) {
echo '<fieldset><strong style="color:red">ERROR: Fields must not be empty</strong></fieldset>';
} else {
	if (isset($_POST['addThisLink'])) {
	echo '<fieldset><strong style="color:green">Link Added</strong></fieldset>';
	}
	if (isset($_POST['editThisLink'])) {
	echo '<fieldset><strong style="color:green">Link Edited</strong></fieldset>';
	}
	if (isset($_GET['checklinks'])) {
	echo '<fieldset><strong style="color:green">All Reciprocal Links Checked</strong></fieldset>';
	}
}
?>




<?php if (!isset($_GET['addlnk']) && !isset($_GET['edit'])) { ?>
<fieldset>
<legend>Link Options</legend>
<img src="images/arrow2.gif" width="9" height="9" alt="" />&nbsp;<a href="index.php?ad=ld&addlnk=1">Add a Link</a><br />
<img src="images/arrow2.gif" width="9" height="9" alt="" />&nbsp;<a href="index.php?ad=ld&checklinks=1">Check All Links for Reciprocal Links</a><br />
</fieldset>







<?php } else if (isset($_GET['addlnk'])) { ?>

<fieldset style="border: 1px solid green;">
<legend>Add Link</legend>
<form action="index.php?ad=ld" method="post" name="addLink">
<table cellpadding="4" cellspacing="0" border="0">
<tr>
<td>
<label for="lFullName">Full Name:</label>
</td>
<td>
<input name="ld_fullName" type="text" id="lFullName" class="adminInput" />
</td>
</tr>
<tr>
<td>
<label for="lEmail">Email:</label>
</td>
<td>
<input name="ld_email" type="text" id="lEmail" class="adminInput" />
</td>
</tr>
<tr>
<td>
<label for="lWebsiteURL">Website URL:</label>
</td>
<td>
<input name="ld_websiteURL" type="text" id="lWebsiteURL" class="adminInput" value="http://" />
</td>
</tr>
<tr>
<td>
<label for="lWebsiteTitle">Website Title:</label>
</td>
<td>
<input name="ld_websiteTitle" type="text" id="lWebsiteTitle" class="adminInput" />
</td>
</tr>
<tr>
<td>
<label for="lWebsiteDescription">Website Description:</label>
</td>
<td>
<textarea name="ld_websiteDescription" rows="6" class="adminInput" id="lWebsiteDescription"></textarea>
</td>
</tr>
<tr>
<td>
<label for="lCategory">Category:</label>
</td>
<td>
<select name="ld_category" id="lCategory">
<option value="nocategory">No Category</option>
<?php 
// repeat cat names options
do { 
	if ($catNames['id'] !== NULL) { ?>
	<option value="<?php echo $catNames['id'] ?>"><?php echo $catNames['name'] ?></option>
<?php }
} while ($catNames = mysql_fetch_assoc($getCatNames)); ?>
</select>
</td>
</tr>
<tr>
<td>
<label for="lReciprocalLink">Reciprocal Link:</label>
</td>
<td>
<input name="ld_reciprocalLink" type="text" id="lReciprocalLink" class="adminInput" value="http://" />
</td>
</tr>
<tr>
<td>
<label for="lCheckReciprocal">Check For Reciprocal Link?:</label>
</td>
<td>
Yes:
<input name="ld_checkReciprocal" type="radio" id="lCheckReciprocal" checked="checked" value="0" />
No:
<input name="ld_checkReciprocal" type="radio" id="lCheckReciprocal" value="1" />
</td>
</tr>
</table>
<input type="hidden" name="addThisLink" value="yes" />
<input value="Add Link" type="submit" class="padSubmit" />
</form>
</fieldset>









<?php } else if (isset($_GET['edit'])) { 

$sql =  sprintf("SELECT * FROM affiliSt_links WHERE id = %s",
           quote_smart($_GET['edit']));
$getEditCat = mysql_query($sql, $databaseConnect) or die(mysql_error());
$editCat = mysql_fetch_assoc($getEditCat);
?>

<fieldset style="border: 1px solid green;">
<legend>Edit Link</legend>
<form action="index.php?ad=ld" method="post" name="addLink">
<table cellpadding="4" cellspacing="0" border="0">
<tr>
<td>
<label for="lFullName">Full Name:</label>
</td>
<td>
<input name="ld_fullName" type="text" id="lFullName" class="adminInput" value="<?php echo $editCat['name'] ?>" />
</td>
</tr>
<tr>
<td>
<label for="lEmail">Email:</label>
</td>
<td>
<input name="ld_email" type="text" id="lEmail" class="adminInput" value="<?php echo $editCat['email'] ?>" />
</td>
</tr>
<tr>
<td>
<label for="lWebsiteURL">Website URL:</label>
</td>
<td>
<input name="ld_websiteURL" type="text" id="lWebsiteURL" class="adminInput"  value="<?php echo $editCat['url'] ?>" />
</td>
</tr>
<tr>
<td>
<label for="lWebsiteTitle">Website Title:</label>
</td>
<td>
<input name="ld_websiteTitle" type="text" id="lWebsiteTitle" class="adminInput" value="<?php echo $editCat['title'] ?>" />
</td>
</tr>
<tr>
<td>
<label for="lWebsiteDescription">Website Description:</label>
</td>
<td>
<textarea name="ld_websiteDescription" rows="6" class="adminInput" id="lWebsiteDescription"><?php echo $editCat['description'] ?></textarea>
</td>
</tr>
<tr>
<td>
<label for="lCategory">Category:</label>
</td>
<td>
<select name="ld_category" id="lCategory">
<option value="nocategory">No Category</option>
<?php 
// repeat cat names options
do { 
	if ($catNames['id'] !== NULL) { ?>
	<option value="<?php echo $catNames['id'] ?>"
	<?php if ($editCat['category'] == $catNames['id']) {
	echo ' selected="selected" ';
	}
	?>
	><?php echo $catNames['name'] ?></option>
<?php }
} while ($catNames = mysql_fetch_assoc($getCatNames)); ?>
</select>
</td>
</tr>
<tr>
<td>
<label for="lReciprocalLink">Reciprocal Link:</label>
</td>
<td>
<input name="ld_reciprocalLink" type="text" id="lReciprocalLink" class="adminInput" value="<?php echo $editCat['reciprocal'] ?>" /> [<a href="<?php echo $editCat['reciprocal'] ?>">view</a>]
</td>
</tr>
<tr>
<td>
<label for="lApprove">Approve This Link?:</label>
</td>
<td>
Yes:
<input name="ld_approve" type="radio" id="lApprove"
	<?php if ($editCat['approved'] == 1) {
	echo ' checked="checked" ';
	}
	?>  value="1" />
No:
<input name="ld_approve" type="radio" id="lApprove"
	<?php if ($editCat['approved'] == 0) {
	echo ' checked="checked" ';
	}
	?> value="0" />
</td>
</tr>
<tr>
<td>
<label for="lCheckReciprocal">Check For Reciprocal Link?:</label>
</td>
<td>
Yes:
<input name="ld_checkReciprocal" type="radio" id="lCheckReciprocal"
	<?php if ($editCat['nocheck'] == 0) {
	echo ' checked="checked" ';
	}
	?>  value="0" />
No:
<input name="ld_checkReciprocal" type="radio" id="lCheckReciprocal"
	<?php if ($editCat['nocheck'] == 1) {
	echo ' checked="checked" ';
	}
	?> value="1" />
</td>
</tr>
</table>
<input type="hidden" name="editThisLink" value="<?php echo $_GET['edit']; ?>" />
<input type="hidden" name="oldCat" value="<?php echo $_GET['c']; ?>" />
<input type="hidden" name="oldApproveStatus" value="<?php echo $editCat['approved']; ?>" />
<input value="Edit Link" type="submit" class="padSubmit" />
</form>
</fieldset>

<?php } ?>











<fieldset>
<legend>Manage Links</legend>

<table cellpadding="2" cellspacing="4" border="0">
<thead><strong>Colour Key</strong></thead>
<tr>
<td style="background-color:#ffffff; border:1px solid #cccccc;">&nbsp;&nbsp;</td>
<td>Link Approved</td>
<td style="background-color:#eeeeee; border:1px solid #cccccc;">&nbsp;&nbsp;</td>
<td>Link Not Approved</td>
<td style="background-color:#F7CFA8; border:1px solid #cccccc;">&nbsp;&nbsp;</td>
<td>No Reciprocal Link</td>
</tr>
</table>

<?php if ($linksDetails) { ?>
<table cellpadding="6" cellspacing="0" border="0" width="100%">
<tr>
<th align="left" valign="top" style="white-space:nowrap">Website Title</th>
<th align="left" valign="top">Website Description</th>
<th align="left" valign="top" style="white-space:nowrap">Date Added</th>
<th align="left" valign="top">Edit/Delete</th>
</tr>
<?php do { 

	// set tr background colour style
	if ($linksDetails['confirmed'] == 0 && $linksDetails['approved'] == 0 && $linksDetails['nocheck'] == 0) {
	$trColour = '#F7CFA8';
	} else if ($linksDetails['confirmed'] == 1 && $linksDetails['approved'] == 0 && $linksDetails['nocheck'] == 0) {
	$trColour = '#eeeeee';
	} else if ($linksDetails['confirmed'] == 0 && $linksDetails['approved'] == 0 && $linksDetails['nocheck'] == 1) {
	$trColour = '#eeeeee';
	} else if ($linksDetails['confirmed'] == 1 && $linksDetails['approved'] == 0 && $linksDetails['nocheck'] == 1) {
	$trColour = '#eeeeee';
	} else if ($linksDetails['confirmed'] == 0 && $linksDetails['approved'] == 1 && $linksDetails['nocheck'] == 0) {
	$trColour = '#F7CFA8';
	} else {
	$trColour = '#ffffff';
	}

?>
<tr style="background-color:<?php echo $trColour; ?>">
<td align="left" valign="top" style="border-top:1px solid #cccccc;">
<a href="<?php echo $linksDetails['url']; ?>" target="_blank"><?php echo $linksDetails['title']; ?></a>
</td>
<td align="left" valign="top" style="border-top:1px solid #cccccc;">
<?php echo $linksDetails['description']; ?>
</td>
<td align="left" valign="top" style="border-top:1px solid #cccccc;">
<?php echo date('d F Y', $linksDetails['added']); ?>
</td>
<td align="left" valign="top" style="border-top:1px solid #cccccc; white-space:nowrap">
[<a href="index.php?ad=ld&edit=<?php echo $linksDetails['id'] ?>&c=<?php echo $linksDetails['category'] ?>">edit</a>] 
[<a href="index.php?ad=ld&delete=<?php echo $linksDetails['id'] ?>&c=<?php echo $linksDetails['category'] ?><?php if ($linksDetails['approved'] == 0) { echo '&count=no'; } ?>">delete</a>]
</td>
</tr>
<?php } while ($linksDetails = mysql_fetch_assoc($getLinksDetails)); ?>
</table>
<?php 



// page numbers
$numofpages = $totalrows / $limit;

if ($numofpages > 1) {
	echo('<div id="pagLinks">');
	
	// previous page link
	if($page != 1){ 
	$pageprev = $page - 1;
	echo("<a href=\"$currentPage?ad=ld&page=$pageprev\">&lt Prev</a> "); 
	}else{
	echo("&lt Prev ");
	}
	
	
	 
	
	for($i = 1; $i <= $numofpages; $i++){
		if($i == $page){
		echo($i." ");
		}else{
		echo("<a href=\"$currentPage?ad=ld&page=$i\">$i</a> ");
		}
	}
	
	// check for remainder results with %
	if(($totalrows % $limit) != 0){
		if($i == $page){
		echo($i." ");
		}else{
		echo("<a href=\"$currentPage?ad=ld&page=$i\">$i</a> ");
		}
	}
	
	// next page link
	if(($totalrows - ($limit * $page)) > 0){
	$pagenext = $page + 1;
	echo("<a href=\"$currentPage?ad=ld&page=$pagenext\">Next &gt;</a>"); 
	}else{
	echo("Next &gt;"); 
	}
	
	echo('</div>');
}



} ?>
</fieldset>